var removeElement = function(nums, val) {
    var i = 0;
    var n = nums.length;
    while (i < n) {
        if (nums[i] == val) {
            nums[i] = nums[n - 1];
            n--
        } else {
            i++;
        }
    }
    return i;
};
nums = [3, 2, 2, 3]

console.log(removeElement(nums, 3));